<?php
namespace App\Http\Controllers\App;
use Illuminate\Support\Facades\Session;
use App\Http\Controllers\Controller;
use App\User;
use App\Http\Requests;
use Auth;

class SiteController extends Controller{

    public function changePassword()
    {
        return view('site.change_password',[
            'user'=>Auth::user()
        ]);
    }

    public function changePasswordCheck(Requests\ChangePasswordRequest $request)
    {
        $user = Auth::user();
        $user->fill($request->validated());
        $user->save();
        Auth::setUser($user);
        return redirect()->route('change_password');
    }

    public function code(\Request $request)
    {
        $str = "3,4,5,6,7,8,9,a,b,c,d,e,f,g";
        $list = explode(",",$str);
        $max = count($list) - 1;
        $verify = "";
        for($i = 0; $i <5;$i ++){
            $rand = mt_rand(0,$max);
            $verify .= $list[$rand];
        }
        Session::put('verifyCode',$verify);
        Session::save();
        $im = imagecreate(58,28);
        $black = imagecolorallocate($im,0,0,0);
        $white = imagecolorallocate($im,255,255,255);
        imagefill($im,0,0,$white);
        imagestring($im,5,10,8,$verify,$black);
        imagepng($im);
        imagedestroy($im);
        response();
        return response('',200,[
            'Content-type'=>'image/png'
        ]);
    }
}